package com.example.leetdemo.finash;

public class Solution1700 {

    public int countStudents(int[] students, int[] sandwiches) {
        int count = students.length;
        int a = 0, b = 0;
        for (int i = 0; i < students.length; i++) {
            a += students[i] == 1 ? 1 : 0;
            b += students[i] == 0 ? 1 : 0;
        }
        for (int i = 0; i < sandwiches.length; i++) {
            if (sandwiches[i] == 1) {
                if (a == 0) {
                    break;
                }
                a--;
            } else {
                if (b == 0) {
                    break;
                }
                b--;
            }
        }
        return a + b;
    }

    /**
     * [1,1,1,0,0,1] students
     * [1,0,0,0,1,1] sandwiches
     */
}
